#ifndef __EssNetwork_H__
#define __EssNetwork_H__

#include "EssAcceptor.h"
#include "EssConnector.h"
#include <map>

class EssNetwork
{
public:
	typedef std::map<SOCKET, EssAcceptor*> AcceptorList;
	typedef AcceptorList::value_type AcceptorValue;
	typedef AcceptorList::iterator AcceptorIterator;

	typedef std::map<SOCKET, EssConnector*> ConnectList;
	typedef ConnectList::value_type ConnectorValue;
	typedef ConnectList::iterator ConnectorIterator;

public:
	EssNetwork();
	virtual ~EssNetwork();

	virtual bool initialize(HWND wnd, UINT message, WORD majorVersion, WORD minorVersion);
	virtual void terminate();
	
	virtual EssAcceptor* exeListen(const char* localIP, u_short port);
	virtual EssConnector* exeConnect(const char* dest_ip, u_short dest_port);
	virtual void removeAcceptor(const EssAcceptor* acceptor);
	virtual void removeConnector(const EssConnector* connector);

	virtual void onAccept(EssAcceptor* acceptor, EssConnector* connector) {}
	virtual void onConnect(EssConnector* connector) {}
	virtual bool onReceive(EssConnector* connector) { return true; }
	virtual void onConnectFailed(EssConnector* connector) {}
	virtual void onDisconnect(EssConnector* connector) {}

	virtual LRESULT handleMessage(WPARAM wParam, LPARAM lParam);

	const WSADATA& getData() const { return mData; }

protected:
	WSADATA			mData;

	AcceptorList	mAcceptors;
	ConnectList		mConnectors;

	HWND			mWnd;
	UINT			mMessage;
};

#endif //__EssNetwork_H__